﻿@{
    Layout = null;
}
@{
    int loginError = 0;
    if (!string.IsNullOrEmpty(Request.GetCookieValue("LoginError")))
    {
        loginError = int.Parse(Request.GetCookieValue("LoginError"));
    }
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    <link href="~/Css/style.css" rel="stylesheet" />
    <link href="~/Css/reset.css" rel="stylesheet" />
    <link href="~/Css/invalid.css" rel="stylesheet" />
    <script src="~/Scripts/jquery.min.js"></script>
    <script src="~/Scripts/jquery.cookie.js"></script>
    <script src="~/Scripts/jquery.hotkeys.min.js"></script>
    <script src="~/Scripts/jaws.js"></script>
    <script type="text/javascript">
        $(function() {
            $("#UserName").focus();
            var login = function() {
                var $userName = $("#UserName");
                var $password = $("#Password");
                var userName = $.trim($userName.val());
                var password = $.trim($password.val());
                if (userName == "") {
                    $.jalert("用户名不能为空");
                    $userName.focus();
                    return;
                }
                if (password == "") {
                    $.jalert("密码不能为空");
                    $password.focus();
                    return;
                }
                var validateCode = "";

                if (@loginError >= 3) {
                    var $validateCode = $("#ValidateCode");
                    validateCode = $.trim($validateCode.val());
                    if (validateCode == "") {
                        $.jalert("验证码不能为空");
                        $validateCode.focus();
                        return;
                    }
                }
                var returnUrl = "@(ViewBag.ReturnUrl)";
                $.jajax({
                    url: "@Url.DomainRouteUrl(AreasConfig.AdminSite, "login", "adminhome")",
                    params: { adminUserName: userName, adminPassword: password, validateCode: validateCode },
                callback: function(ret) {
                    if (!ret) {
                        return;
                    }
                    if (ret.data > 0) {
                        if (returnUrl) {
                            window.location.href = returnUrl;
                        } else {
                            window.location.href = "@Url.DomainRouteUrl(AreasConfig.Admin, "Index", "Home")";
                        }
                    } else {
                        $.jalert(ret.message);
                        window.location.reload();
                    }
                }
            }); 
            }

            $("#Login").bind("click", function() {
                login();
            });
            jQuery.hotkeys.add("return", function() {
                login();
            });
        });
    </script>
</head>
<body>
    <div id="login-wrapper">
        <div id="login-top">
            <a href="@WebConfig.WebSite"><img id="logo" src="/images/logo2.jpg"></a>
        </div>
        <div style="background: #b41005; width: 100%; height: auto; overflow: hidden; padding: 20px 0;">
            <div id="login-content">
                <form>
                    <p>
                        <label>用户名</label>
                        <input class="text-input" id="UserName" type="text">
                    </p>
                    <div class="clear"></div>
                    <p>
                        <label>密&nbsp;&nbsp;&nbsp;码</label>
                        <input class="text-input" id="Password" type="password">
                    </p>
                    <div class="clear"></div>
                    @{
                        if (loginError >= 3)
                        {
                            <p>
                                <label>验证码</label>
                                <input class="text-input" id="ValidateCode" type="text">
                            </p>
                            <div class="clear"></div>
                            <p style="padding-left: 70px;">
                                <img id="Code" src="@Url.DomainRouteUrl(AreasConfig.AdminSite, "ValidateCode", "AdminHome")"/>
                                <a href="javascript:void(0)" onclick="document.getElementById('Code').src = '@Url.DomainRouteUrl(AreasConfig.AdminSite, "ValidateCode", "AdminHome")' + '?c=' + Math.random(); " style="color: #fff; font-size: 12px;">看不清换一张</a>
                            </p>
                            <div class="clear"></div>
                        }
                    }
                    <p id="remember-password">
                        <input type="checkbox">记住
                    </p>
                    <div class="clear"></div>
                    <p style="padding-left: 70px;">
                        <input class="button" id="Login" type="button" value="登  录">
                    </p>
                </form>
            </div>
        </div>
    </div>
</body>
</html>
